package com.wteam.PoJo.DTO;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wteam.PoJo.DO.Goods;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(description = "分页实体类")
public class PageQuery {

    @ApiModelProperty(value = "页码", required = true)
    private Integer page = 1;

    @ApiModelProperty(value = "一页条数", required = true)
    private Integer pageSize = 10;

    @ApiModelProperty(value = "升降字段", required = false)
    private String sortBy;

    @ApiModelProperty(value = "是否升降", required = false)
    private Boolean isAsc = true;


    public <T> Page<T> toMpPage() {

        Page<T> page1 = Page.of(page, pageSize);

        if (StrUtil.isNotBlank(sortBy)&&isAsc!=null) {
            page1.addOrder(new OrderItem(sortBy, isAsc));
        } else {
            page1.addOrder(new OrderItem("create_time", false));

        }
        return page1;

    }


}
